package com.example.a28796.beautiful.styAdapter;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.stybean.HuodongBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lenovo on 2016/8/31.
 */
public class HuodongAdapter extends RecyclerView.Adapter<HuodongAdapter.MyViewHolder> {
    private Context context;
    private List<HuodongBean.ObjBean.ListDataBean> mData;
    private List<Integer> mHeight;


    public interface OnItemClickLitener
    {
        void onItemClick(View view, int position);
        void onItemLongClick(View view , int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }


    public HuodongAdapter(Context context, List<HuodongBean.ObjBean.ListDataBean> mData, List<Integer> mHeight) {
        this.context = context;
        this.mData = mData;
        this.mHeight = mHeight;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_huodong, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        String url = mData.get(position).getPhoto().getUrl();
        Picasso.with(context).load(url).into(holder.ivShow);
        holder.tvName.setText(mData.get(position).getArticleGroup().getTitle());
        if (mOnItemClickLitener != null)
        {
            holder.itemView.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener()
            {
                @Override
                public boolean onLongClick(View v)
                {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
        holder.itemView.setBackgroundResource(R.drawable.item_back);


    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView ivShow;
        private TextView tvName;
        public MyViewHolder(View itemView) {
            super(itemView);
            ivShow = (ImageView) itemView.findViewById(R.id.iv_item_huodong_show);
            tvName = (TextView) itemView.findViewById(R.id.tv_item_huodong_name);
        }
    }
}
